package com.and9.mchen.mcmusic.struts.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.and9.mchen.mcmusic.constant.MusicManagerConstant;
import com.and9.mchen.mcmusic.exception.ServiceException;
import com.and9.mchen.mcmusic.manager.ServiceManager;
import com.and9.mchen.mcmusic.service.IMusicManagerService;
import com.and9.mchen.mcmusic.struts.action.base.BaseAction;
import com.and9.mchen.mcmusic.struts.model.MusicHomeModel;
import com.and9.mchen.mcmusic.vo.OmitAlbumBean;
import com.and9.mchen.mcmusic.vo.OmitMusicStyleBean;
import com.and9.mchen.mcmusic.vo.OmitSongBean;
import com.opensymphony.xwork2.ModelDriven;

@ParentPackage(value="base_struts")
@Namespace(value="/home")
@Results(
	{@Result(name="index",location="/WEB-INF/home/index.jsp")}
)
public class HomeAction extends BaseAction implements ModelDriven<MusicHomeModel>{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 2142771650643445554L;
	private IMusicManagerService musicManagerService=null;
	private MusicHomeModel model=new MusicHomeModel();
	
	public HomeAction(){
		musicManagerService=ServiceManager.getMusicManagerService();
	}
	
	@Action(value="index")
	public String index() throws ServiceException, Exception{
		
		List<OmitAlbumBean> latestOmitAlbumBeans=musicManagerService.
				getNLatestOmitAlbumBeans(MusicManagerConstant.OMIT_ALBUM_PAGE_COUNT);
		List<OmitSongBean> latestOmitSongBeans=musicManagerService.
				getNLatestOmitSongBeans(MusicManagerConstant.OMIT_SONG_PAGE_COUNT);
		List<OmitMusicStyleBean> allMusicStyleBeans=musicManagerService.getAllMusicStyleBeans();
		
		model.setAllMusicStyleBeans(allMusicStyleBeans);
		model.setLatestOmitAlbumBeans(latestOmitAlbumBeans);
		model.setLatestOmitSongBeans(latestOmitSongBeans);
		
		Request.put("model", model);

		return "index";
	}

	public MusicHomeModel getModel() {
		return model;
	}
	
}
